{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "LMIpU4kXLSRa"
   },
   "outputs": [],
   "source": [
    "#@title 一、下载源码\n",
    "# # 并解压"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 172820,
     "status": "ok",
     "timestamp": 1698209589908,
     "user": {
      "displayName": "ba ba",
      "userId": "00513101234799394381"
     },
     "user_tz": -480
    },
    "id": "SXSzH1vTEG5z",
    "outputId": "5288e278-9152-4eb9-eea5-200129d64848"
   },
   "outputs": [],
   "source": [
    "#@title 二、安装依赖\n",
    "# 因为google升级了pytorch 但是代码是用的torch2.0.1写得，所以需要降低版本。\n",
    "#torch版本如果不是2.0.1+cu118，，则重新安装该版本\n",
    "pip install -r requirements.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "zHkXn-FFDxu4"
   },
   "outputs": [],
   "source": [
    "#@title 三、数据处理\n",
    "# 1、 用split_video.py 切割视频\n",
    "# 2、 用sample.py 生成 filelists\n",
    "\n",
    "# !wget \"https://www.adrianbulat.com/downloads/python-fan/s3fd-619a316812.pth\" -O \"./face_detection/detection/sfd/s3fd.pth\"\n",
    "# 3、数据处理\n",
    "python  preprocess.py  --data_root  ./data  --preprocessed_root ./preprocessed_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "7sfp7gAYqcxq"
   },
   "outputs": [],
   "source": [
    "#@title 四、判别器训练\n",
    "# 如果爆显存 ，请将 hparams.py的 batch_size 改成4 或者更小。\n",
    "python color_syncnet_train.py --data_root  preprocessed_data  --checkpoint_dir color_checkpoints\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#@title 五、生成器训练\n",
    "# 如果爆显存 ，请将 hparams.py的 batch_size 改成4 或者更小。\n",
    "python wav2lip_train.py  --data_root  preprocessed_data  --checkpoint_dir  final_checkpionts  --syncnet_checkpoint_path  color_checkpoints/checkpoint_step000699000.pth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#@title 六、推理\n",
    "# 如果爆显存 ，请将inference.py的 batch_size 改成4 或者更小。\n",
    "python inference.py --checkpoint_path  final_checkpionts/checkpoint_step000360000.pth  --face ./input/555.mp4  --audio  ./input/555.wav"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看文件夹下面， 每个子文件夹下面的文件数量\n",
    "for d in */ ; do echo \"$d\"; find \"$d\" -maxdepth 1 -type f | wc -l; done\n",
    "#  查看音频采样\n",
    "ffmpeg -i audio.wav"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 跨区域拷贝数据\n",
    "# 拷贝到那个区的项目\n",
    "ssh -p 39861 root@connect.westb.seetacloud.com\n",
    "# 从此项目拷贝到目标项目中\n",
    "scp -rP 39861 /root/autodl-tmp/wav2lip384/final_checkpionts/checkpoint_step000480000.pth   root@connect.westb.seetacloud.com:/rootautodl-tmp/wav2lip384"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# tensorboard显示loss\n",
    "tensorboard --port 7860 --logdir /root/autodl-tmp/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转成16000赫兹"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "provenance": [
    {
     "file_id": "1bY0Kw2oWWrpKS6ne-TBCbW-iFyXIrRR7",
     "timestamp": 1680665453952
    }
   ]
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
